<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8" />
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<script src="/node_modules/s94-js/s94.js" type="text/javascript" charset="utf-8"></script>
	<!--公共部分-->
	<script src="/html/admin/common/common.js" type="text/javascript" charset="utf-8"></script>
	<link  href="/html/admin/common/common.css" rel="stylesheet" type="text/css" />
	<title>后台-订单-添加</title>
</head>
<body>
<div class="frame-body">
	<div id="app">
		<forms ref="forms" :config="config" @submit:forms="onsubmit" btntxt="添加"></forms>
	</div>
	<script type="text/javascript">
		var app = vue_app({
			data: function(){
                let model = {name:$get('model_name'), alias:$get('model_alias','')};
                document.title = '后台-'+model.alias+'订单-添加';
                let list_url = '/html/admin/model_base/index.html?model_name='+model.name+'&model_alias='+model.alias;
                return {
                    model: model,
                    config: {
                        user_id: {label:'指定用户',name:'user_id',config:'/html/admin/user/index.html',type:'list_id',tips:''},
                        [model.name+'_id']: {label:'指定'+model.alias,name:model.name+'_id',config:list_url,type:'list_id',tips:'',onchange:this.get_field_config},
                        num: {label:'数量',name:'num',type:'text_one',config:'number',value:1,tips:'最小为1'},
                    },
                }
			},
			methods: {
				param(data){
					data = data || {};
					data.model_name = this.model.name;
					data.model_alias = this.model.alias;
					return $.param(data);
				},
                add_after(res){
                    this.$refs['forms'].init();
                    if (is_iframe){
						iframe.exe('index.html?'+this.param(), 'app.$refs.list_url.select');
						iframe.hide(location.href);
                    }
                },
                onsubmit: function(formData){
                    let app = this;
                    ajax({url:'/admin/'+this.model.name+'/order_add', type: 'post', data: formData}, this.add_after, function (res){
                        if (res.errors) app.$refs['forms'].errors = res.errors;
                    })
                },
                get_field_config(row, id){
                    let app = this;
                    ajax({url:'/admin/'+app.model.name+'/field_config?action=add&table=1&'+app.model.name+'_id='+id, cache:true}, function(res){
                        app.model = res.data.model;
                        document.title = '后台-'+app.model.alias+'订单-添加';
                        $.each(app.config, function (v,k){
                            if (!~['user_id',app.model.name+'_id','num'].indexOf(k)) delete app.config[k];
                        })
                        $.each(res.data.cols, function(v){
                            v.name = v.name.replace('.','_');
                            app.config[v.name] = {
                                label: v.label,
                                name: v.name,
                                tips: v.tips,
                                type: v.type,
                                config: v.config,
                                value:v.value,
                            };
                        })
                        setTimeout(function(){app.$refs['forms'].set_init_value()})
                        return false;
                    })
                },
			},
            watch: {

            },
            mounted(){
                let app = this;
            }
		});
	</script>
</div>
</body>
</html>
